package com.github.tvbox.osc.ui.activity

import android.content.Intent
import android.os.Bundle
import com.github.tvbox.osc.R
import com.github.tvbox.osc.base.App.Companion.getInstance
import com.github.tvbox.osc.base.BaseActivity
import io.github.source.media.bean.MediaBean

/**
 * @ClassName: DetailActivityKt
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author: huangrongcai
 * @date: 2025/6/15
 *
 * @Copyright: 黄嵘才（HuangRc)
 */
class DetailActivityKt : BaseActivity() {
    companion object {
        /**
         * ID
         */
        var VOD_ID = "vodId"
        /**
         * ID
         */
        var VOD_BEAN = "VOD_BEAN"

        /**
         * 源站
         */
        var SITE_KEY = "siteKey"

        /**
         * 名称（关键字等）
         */
        var QUERY_WORD = "queryWord"
        /**
         * 跳转到媒体详情
         *
         * @param vodId   点播ID
         * @param siteKey 源站
         */
        fun start(vodId: String?, siteKey: String?) {
            val intent = Intent(getInstance(), DetailActivityKt::class.java)
            intent.putExtra(VOD_ID, vodId)
            intent.putExtra(SITE_KEY, siteKey)
            intent.putExtra(QUERY_WORD, "") /*名称（关键字等）*/
            val bundle = Bundle()
            bundle.putString(VOD_ID, vodId)
            bundle.putString(SITE_KEY, siteKey)
            bundle.putString(QUERY_WORD, "")
            intent.putExtras(bundle)
            getInstance()!!.startActivity(intent)
        }
        /**
         * 跳转到媒体详情
         *
         * @param vodId   点播ID
         * @param siteKey 源站
         */
        fun start(bean: MediaBean?) {
            val intent = Intent(getInstance(), DetailActivityKt::class.java)
            intent.putExtra(VOD_BEAN, bean)
            val bundle = Bundle()
            bundle.putSerializable(VOD_BEAN, bean)
            intent.putExtras(bundle)
            getInstance()!!.startActivity(intent)
        }
    }

    override fun getLayoutResID(): Int {
        return R.layout.activity_home
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
    }

    override fun init(savedInstanceState: Bundle?) {
        // 默认加载首页 Fragment
        if (savedInstanceState == null) {
            val bundle = intent.extras
            val VOD_ID = bundle?.getString(VOD_ID, "")
            val SITE_KEY = bundle?.getString(SITE_KEY, "")
            val QUERY_WORD = bundle?.getString(QUERY_WORD, "")
            val fragment = DetailActivityFragment.newInstance(VOD_ID,SITE_KEY)
            getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.skin_fragment_container, fragment)
                .commitNowAllowingStateLoss()
        }
    }
}